package dxn.nl.file.api;

import dxn.boot.common.entity.*;
import dxn.boot.starter.web.control.BaseControl;
import dxn.boot.starter.web.security.AuthUtils;
import dxn.nl.file.biz.vo.CsExportModelUserBindVo;
import dxn.nl.file.service.AppModeOrgBindService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/mode/org")
@Tag(name = "模块绑定网点管理", description = "模块绑定网点管理")
public class AppModelOrgControl extends BaseControl {

    @Resource
    private AppModeOrgBindService appModeOrgBindService;

    @Operation(summary = "模块绑定网点")
    @RequestMapping(value = "/modeBindOrg", method = RequestMethod.POST)
    public BaseResult<String> modeBindOrg(@RequestBody @Valid CsExportModelUserBindVo pageQuery) {

        AuthUser userDetails = AuthUtils.getCurrentUser();
        if(!"999999".equals(userDetails.getOrgCode()))
        {
            return BaseResult.fail("没有权限操作");
        }

       String result = appModeOrgBindService.modeBindOrg(pageQuery);

        return checkAndReturnResult(result);
    }

    @Operation(summary = "模块解绑定网点")
    @RequestMapping(value = "/modeUnBindOrg", method = RequestMethod.POST)
    public BaseResult<List<CsBaseCodeNameDto>> modeUnBindOrg(@RequestBody @Valid CsExportModelUserBindVo pageQuery) {

        AuthUser userDetails = AuthUtils.getCurrentUser();
        if(!"999999".equals(userDetails.getOrgCode()))
        {
            return BaseResult.fail("没有权限操作");
        }

        String result = appModeOrgBindService.modeUnBindOrg(pageQuery);

        return checkAndReturnResult(result);
    }

    @Operation(summary = "分页查询模块没有绑定的网点")
    @RequestMapping(value = "/pageModeUnBindOrg", method = RequestMethod.POST)
    public BaseResult<String> pageModeUnBindOrg(@RequestBody @Valid CsBasePageQuery<CsExportModelUserBindVo> pageQuery) {

        AuthUser userDetails = AuthUtils.getCurrentUser();
        if(!"999999".equals(userDetails.getOrgCode()))
        {
            return BaseResult.fail("没有权限操作");
        }

        CsBasePageResult<CsBaseCodeNameDto> result = appModeOrgBindService.pageModeUnBindOrg(pageQuery);

        return BaseResult.success(result);
    }

    @Operation(summary = "分页查询模块绑定的网点")
    @RequestMapping(value = "/pageModeBindOrg", method = RequestMethod.POST)
    public BaseResult<List<CsBaseCodeNameDto>> pageModeBindOrg(@RequestBody @Valid CsBasePageQuery<CsExportModelUserBindVo> pageQuery) {

        AuthUser userDetails = AuthUtils.getCurrentUser();
        if(!"999999".equals(userDetails.getOrgCode()))
        {
            return BaseResult.fail("没有权限操作");
        }

        CsBasePageResult<CsBaseCodeNameDto> result = appModeOrgBindService.pageModeBindOrg(pageQuery);

        return BaseResult.success(result);
    }

}
